package com.sky.controller.admin;


import com.sky.dto.CouponDTO;
import com.sky.dto.CouponPageQueryDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 通用接口
 */
@RestController
@RequestMapping("/admin/coupon")
@Api(tags = "优惠券接口")
@Slf4j
public class CouponController {

    // 查看，增加，删除（只是下架，不让显示不让继续领取），（不能修改）

    @Autowired
    private CouponService couponService;

    @GetMapping("/get")
    @ApiOperation("获取所有优惠券")
    public Result<PageResult> getPages(CouponPageQueryDTO couponPageQueryDTO) {
        log.info(" == get all coupons ", couponPageQueryDTO);

        PageResult pageResult = couponService.pageQuery(couponPageQueryDTO);

        return Result.success(pageResult);
    }

    @PostMapping("/add")
    @ApiOperation("增加优惠券")
    public Result<String> add(@RequestBody CouponDTO couponDTO) {
        log.info(" == add a coupons ", couponDTO);
        if(couponService.addCoupon(couponDTO)) {
            return Result.success();
        }
        return Result.error("增加失败");
    }

    @PostMapping("/delete")
    @ApiOperation("删除优惠券")
    public Result<String> delete(@RequestBody Long couponID) {
        log.info(" == remove a coupons ", couponID);
        if(couponService.deleteCoupon(couponID)) {
            return Result.success();
        }
        return Result.error("删除失败");
    }


}
